import React, { useEffect } from 'react';
import { useIsFocused ,useNavigation} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Pyq from './pyq.js';
import Search from './search.js';
import HotText from './hotText.js';
import PostDetail from './PostDetail.js';
import SearchContent from './searchContent.js';
import SearchPlateContent from './searchPlateContent.js';
import ChooseplateBoard from './chooseBoardPlate.js';
const Stack = createStackNavigator();

export default function App() {
  const navigation = useNavigation();
  const isFocused = useIsFocused();

  useEffect(() => {
    const parent = navigation.getParent(); // 获取父导航器
    if (parent && isFocused) {
      parent.setOptions({ tabBarVisible: false });
    } else if (parent) {
      parent.setOptions({ tabBarVisible: true });
    }
  }, [isFocused, navigation]);

  return (
    <Stack.Navigator>
      <Stack.Screen
        name="Pyq"
        component={Pyq}
        options={{
          headerShown: true,
          headerTitle: '朵朵校友圈',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
        }}
      />
      <Stack.Screen
        name="hotText"
        component={HotText}
        options={{
          headerShown: true,
          headerTitle: '朵圈热榜',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
        }}
      />
      <Stack.Screen
        name="Search"
        component={Search}
        options={{
          headerShown: true,
          headerTitle: '搜索与板块',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
        }}
      />
      <Stack.Screen
        name="PostDetail"
        component={PostDetail}
        options={{
          headerShown: true,
          headerTitle: '朵朵校友圈',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
          tabBarVisible: false
        }}
      />
      <Stack.Screen
        name="SearchContent"
        component={SearchContent}
        options={{
          headerShown: true,
          headerTitle: '搜索结果',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
          tabBarVisible: false
        }}
      />
      <Stack.Screen
        name="SearchPlateContent"
        component={SearchPlateContent}
        options={{
          headerShown: true,
          headerTitle: '热门板块',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
          tabBarVisible: false
        }}
      />
      <Stack.Screen
        name="ChooseplateBoard"
        component={ChooseplateBoard}
        options={{
          headerShown: true,
          headerTitle: '选择板块',
          headerTitleAlign: 'center',
          headerStyle: {
            backgroundColor: '#EB7A76',
          },
          headerTintColor: '#fff',
          tabBarVisible: false
        }}
      />

    </Stack.Navigator>
  );
}